import matplotlib.pyplot as plt
import numpy as np
import cv2 as cv
%matplotlib inline
def show_img(img):
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)
fix_img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
ax.imshow(fix_img)
def show_grey_img(img):
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)
fix_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ax.imshow(fix_img, cmap ="gray")
img = cv.imread("C:/Users/Jaysurya/Desktop/example_camscanner.PNG")
show_img(img)
cross = cv.imread("DATA/crossword.jpg")
show_img(cross)
cross1 = cv.imread("DATA/crossword.jpg")
show_grey_img(cross1)
cross1.max()
cross1.mean()
return1, cross2 =cv.threshold(cross1, 165, 255, cv.THRESH_BINARY)
show_grey_img(cross2)
print(cross2.max()," , ", cross2.min())
fix_img = cv.cvtColor(cross2, cv.COLOR_BGR2GRAY)
#img = plt.imshow(fix_img,cmap="gray")
cv.imwrite("scanned.jpg",cross2)
img1 = cv.cvtColor(cv.imread("DATA/gorilla.jpg"), cv.COLOR_BGR2RGB)
img2 = cv.resize(cv.cvtColor(cv.imread("DATA/watermark_no_copy.png"), cv.COLOR_BGR2RGB),(600,600))
img1.shape
plt.imshow(img1)
x_offset = 1925 - 600
y_offset = 1295 - 600
img2.shape
rows, columns, channel = img2.shape
roi = img1[y_offset:1295,x_offset:1925]
plt.imshow(roi)
img2_gray = cv.cvtColor(img2,cv.COLOR_RGB2GRAY)
plt.imshow(img2_gray,cmap="gray")
masked = cv.bitwise_not(img2_gray)
plt.imshow(masked,cmap="gray")
masked.shape
white_back = np.full(img2.shape,255,dtype = np.uint8)# have a background for all 3 color channe;s
back_full = cv.bitwise_or(white_back,white_back,mask = masked) # place the masked image onto the white channel background
back_full.shape
white_back.shape
plt.imshow(white_back)
plt.imshow(back_full)
front = cv.bitwise_or(img2,img2,mask=masked)
plt.imshow(front)
final_roi = cv.bitwise_or(roi,front)
plt.imshow(final_roi)
big_img = img1
small_img = final_roi
big_img[y_offset:y_offset+600,x_offset:x_offset+600] = small_img
plt.imshow(big_img)